Thread: Tx/Rx from/to USB port?

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    110

    Tx/Rx from/to USB port?

    Hi, I am designing a device which I'd like to control from the USB port. I'll use a simple command prompt program in C. Where do I get started with transmitting and receiving data from/to the USB port?

    It's intended for windows 2000, and all newer versions (Mainly 2000, XP, and Vista). In terms of programming does it make a difference if it's USB 1.5 or USB 2.0?


    Thanks
    PHI is one 'H' of alot more interesting than PI!

  2. #2
    Registered User
    Join Date
    Jan 2008
    Posts
    28
    I don't know if this will help you very much, but this is what a quick google search returned:

    http://www.delcom-eng.com/DelcomCD/G.../USBPRGMNL.pdf

    The focus of the document is how to read/write to their device but...... you should be able to get a better understanding of how usb communication actually works. They also have listed a method to retrieve all device id's that you may be able to scan through.

    I've not dealt with USB programming myself, but my understanding is that the communication is done through a 'file' that is constantly being read from/written to. I saw a thread in a linux forum where the user said he just uses fopen() on the device name (/dev/usb0) and reads the stream.

    Hope this helps!
    -Feen

  3. #3
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Quote Originally Posted by Feengur View Post
    I don't know if this will help you very much, but this is what a quick google search returned:

    http://www.delcom-eng.com/DelcomCD/G.../USBPRGMNL.pdf

    The focus of the document is how to read/write to their device but...... you should be able to get a better understanding of how usb communication actually works. They also have listed a method to retrieve all device id's that you may be able to scan through.

    I've not dealt with USB programming myself, but my understanding is that the communication is done through a 'file' that is constantly being read from/written to. I saw a thread in a linux forum where the user said he just uses fopen() on the device name (/dev/usb0) and reads the stream.

    Hope this helps!
    -Feen
    One warning about your advice here (which is fine in and of itself): On Linux/*NIX the 'tao' so to speak is that *everything* is treated as a file (sockets, devices, everything) and since the OP said he was on Windows I don't know that it will apply there...just trying to save some misunderstanding...
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Feengur View Post
    I've not dealt with USB programming myself, but my understanding is that the communication is done through a 'file' that is constantly being read from/written to. I saw a thread in a linux forum where the user said he just uses fopen() on the device name (/dev/usb0) and reads the stream.
    Sure, but nb you must also write an appropriate kernel driver or that file cannot exist! (again, that's wrt linux)
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    28
    Thanks for the info jeff and MK27!
    Last edited by Feengur; 02-23-2010 at 03:45 PM. Reason: had to thank MK27 as well :)

  6. #6
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    libusb

    Supposedly there's a windows port: LibUsb-Win32

  7. #7
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Are you implementing the whole USB stack on your microcontroller or whatever you are using?

    I am doing something similar and decided to go with serial instead (serial to USB converter on the computer side). Much easier on both sides, just 2 wires to worry about (Tx, Rx) if you don't need flow control, and none of that handshaking and framing stuff. You can just wire it up to a MAX232 and the output can go into a UART directly. On the computer side you can use something like libserial, which makes it almost too easy.

  8. #8
    Registered User
    Join Date
    Oct 2008
    Posts
    110
    Thanks for all the replies. Basically at the computer side, I need to sent and recieve data from/to a radio transceiver, with a 4 wire SPI interface. Unfortunately, while RS232 would be easier to use, my specification requires that I must interface with USB, and while USB-serial, and even USB-SPI adapters are available, I am required to do the legwork myself. This will require me to sit an MCU between the USB and radio transceiver, to perform the conversion.

    I'm planning to use an ATMega16U4 or ATMega32U4 AVR MCU, both of which can interface directly with USB. I will then need to code the AVR to perform the conversion from USB to SPI, and write a program on windows to send and receive the data via usb to/from the software.

    I thought it would be as simple as including a windows library whose library functions allow communication with the USB host controller. e.g. being able to call a function such as SendByte(). Is this not the case?

    Thanks

    (@ Epy, sorry I missed your post... thats the kind of thing I had in mind, definately worth looking into, thanks)
    Last edited by bertazoid; 02-24-2010 at 08:29 AM.
    PHI is one 'H' of alot more interesting than PI!

  9. #9
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    I am using an ATmega328 myself, but my development board has a USB-TTL FTDI chip built-in. As far as I understand, the USB protocol will take A LOT of work (establishing connections, etc). It's not simply a Rx/Tx pair like RS-232. Data is also sent in packets.

    It's certainly doable... people even implemented a USB host on a microcontroller, but just making sure you know what you are getting yourself into .

    Oh and I think you will need to write a driver on the computer side, too. The FTDI chip has its own driver (so it appears as a serial port on a computer).

    What do you mean it can interface directly with USB?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Comodo Firewall Vulnerability (Port 0)
    By Mario F. in forum Tech Board
    Replies: 0
    Last Post: 11-11-2009, 08:56 AM
  2. Parallel Port to USB controller and outb()
    By coletek in forum Linux Programming
    Replies: 1
    Last Post: 06-05-2009, 06:57 AM
  3. FTP program
    By jakemott in forum Linux Programming
    Replies: 14
    Last Post: 10-06-2008, 01:58 PM
  4. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  5. Programming the USB Port
    By outerspace in forum C++ Programming
    Replies: 2
    Last Post: 01-23-2006, 02:17 PM